@extends('layouts.admin')
@push('morecss')
    <link href="{{ mix('css/admin/material_news.css') }}" rel="stylesheet">
@endpush

@push('morescript')
    <script src="//cdn.tudouyu.cn/masonry-layout/dist/masonry.pkgd.min.js"></script>
    <script src="//cdn.tudouyu.cn/imagesloaded/imagesloaded.pkgd.min.js"></script>
    <script type="application/javascript">
        let page_params = {
            @can('admin.wxmaterialnews.index')
            url_list: '{{ route('admin.wxmaterialnews.index') }}',
            @endcan
            @can('admin.wxmaterialnews.create')
            url_add: '{{ route('admin.wxmaterialnews.create') }}',
            @endcan
            @can('admin.wxmaterialnews.update')
            url_edit: '{{ route('admin.wxmaterialnews.update') }}',
            @endcan
            @can('admin.wxmaterialnews.destroy')
            url_del: '{{ route('admin.wxmaterialnews.destroy') }}',
            @endcan
            @can('admin.wxmaterialnews.upwx')
            url_upwx: '{{ route('admin.wxmaterialnews.upwx') }}',
            @endcan
            @can('admin.wxmaterialnews.sync')
            url_sync: '{{ route('admin.wxmaterialnews.sync') }}',
            @endcan
            catList:@json($catList)
        }
    </script>
    <!-- require page js -->
    <script src="{{ mix('js/admin/wxmaterialnews_index.js') }}"></script>
@endpush
@section('content')
    <div class="wrapper wrapper-content animated fadeInRight ecommerce">
        <div class="ibox-content m-b-sm border-bottom">
            <div class="row">
                <div class="col-sm-4">
                    @can('admin.wxmaterialnews.create')
                        <a class="btn btn-primary" id="btn-add" href="{{ route('admin.wxmaterialnews.create') }}"><i class="fa fa-plus"></i> 添加图文</a>
                    @endcan
                    @can('admin.wxmaterialnews.sync')
                        <button class="btn btn-primary" type="button" id="btn-sync" v-on:click="sync"><i class="fa fa-cloud-download"></i>
                            拉取微信端图文
                        </button>
                    @endcan
                </div>
            </div>
        </div>
        <div class="ibox-content m-b-sm border-bottom">
            <div class="row">
                <div class="col-sm-12">
                    同步图文素材时，建议先同步拉取图片素材，然后再同步图文素材，减少接口请求次数。
                </div>
            </div>
            <div class="hr-line-dashed"></div>
            <div class="row">
                <div class="col-sm-4">
                    <div class="form-group">
                        <label class="control-label" for="keyword">关键字</label>
                        <input type="text" id="keyword" name="keyword" v-model="searchParams.keyword" placeholder="请输入搜索关键字"
                               class="form-control">
                    </div>
                </div>
                <div class="col-sm-4">
                    <div class="form-group">
                        <label class="control-label" for="product_name">分类</label>
                        <treeselect v-model="searchParams.catId" :options="cat_list" :normalizer="catNormalizer" placeholder="选择素材分类..." />
                    </div>
                </div>
                <div class="col-sm-2">
                    <div class="form-group">
                        <label class="control-label" for="product_name">&nbsp;&nbsp;</label>
                        <div>
                            <button class="btn btn-primary" type="button" id="btn-search" v-on:click="search"><i class="fa fa-search"></i>
                                搜索
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="ibox-content m-b-sm border-bottom">
            <div class="row grid" v-masonry transition-duration="0.3s" item-selector=".grid-item">
                <div class="col-md-4 grid-item" v-for="(item, index) in material_list" v-masonry-tile>
                    <material-preview v-bind:material-data="item" :is-edit="true">
                        <div class="m-t text-right">
                            <button v-on:click="upwx(item.material_id)" v-show="page_params.url_upwx" class="btn btn-default btn-sm">
                                <i class="fa fa-cloud-upload"></i>
                                上传
                            </button>
                            <a class="btn btn-default btn-sm" v-show="page_params.url_edit" :href="page_params.url_edit + '?materialId=' + item.material_id">
                                <i class="fa fa-pencil"></i>
                                编辑
                            </a>
                            <button v-on:click="del(item.material_id)" v-show="page_params.url_del" class="btn btn-default btn-sm">
                                <i class="fa fa-trash"></i>
                                删除
                            </button>
                        </div>
                    </material-preview>
                </div>

            </div>
            <div class="row text-center">
                <pagination :pagination="pagination" :callback="query" :options="paginationOptions"></pagination>
            </div>
        </div>
    </div>
@endsection